

// import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
// import {getBounds} from '@/utils/cesium-map'
// import {getVrDataV2,getVrInfo,setVrCollect,getVrCollectList } from '@/api/vr'
// import {useAccountStore} from '@/stores'
// import { ElMessage } from 'element-plus'
// import {decryptData} from '@/utils/utils'


interface ZFVrModel {
    id:string,
    type:number,
    name:string,
    vr_url:string,
    h5_url:string,
    is_collect:boolean,
    lt_id:number,
    gt_id:number,
}

export interface ZFVrCollectModel {
    id:string,
    data_id:string,
    data_type:number,
    vr:ZFVrModel,
}


export interface ZFPointModel{
    visible: boolean,
    position: number[],
    text:object,
    icon:object,
    extData:object,
}



export const useVrStore = defineStore('vr', {
    state: () => {
        return {
            visible:false,
            points:[] as ZFVrModel[],
            labels:[] as [],
            model:{} as ZFVrModel,
            collects:[] as ZFVrCollectModel[],
            page:1,
            
        }
    },
    getters:{
        url:(state)=>{
            if (state.model.type == 0 || state.model.type == 2) {
             return state.model.vr_url;   
            }
            return state.model.h5_url
        }
    },
    actions: {
       ///开始vr 
        openVr(){
            // let accountStore = useAccountStore();
            // if (!accountStore.isLogin) {
            //     ElMessage.error('请登录账户')
            //     return;
            // }
            // this.visible = !this.visible
            // if(this.visible){
            //     this.markerInit()
            //     moveEnd().addEventListener(this.markerInit)
            // }else{
            //     moveEnd().removeEventListener(this.markerInit)
            //     this.points = []
            // }
        },
        clickMarker(){
            alert("clickMarker")
        },
        //初始化获取vr数据
        markerInit(){
            // let bounds = getBounds();
            // console.log("------bounds",bounds)
            // this.getVrData(bounds);
        },
        ////获取vr数据
       async getVrData(params:any){
        console.log("开始获取vr数据",params)
            // if (!this.visible) {
            //     return;
            // }
            // let that = this;
            // //  remove(this.points);
            //  var res = await getVrDataV2(params) as any;
            //  if (res.code == 200) {
            //     console.log("res",res)

            //     this.points = res.data.map((res:any)=>{
            //         res.position = { lng: res.gt_id, lat: res. lt_id}
            //         res.pixelSize = 8
            //         res.color = (res.type == 0 || res.type == 1) ? '#3a5bff' : 'red'
            //         res.outlineColor = 'white'
            //         res.outlineWidth = 2
            //         return res
            //     })
    

                // console.log("开始数据",res.data.length)
                // this.labels = res.data.filter((res:any) => res.name != '').map((res:any)=>{
                //     res.position = { lng: res.gt_id, lat: res. lt_id}
                //     res.text = res.name
                //     res.fillColor= 'white'
                //     res.font = '6px sans-serif'
                //     res.outlineColor = 'black'
                //     res.outlineWidth = 5
                //     // res.labelStyle = 1
                //    return res;
                // })
                // console.log("结束 ",this.labels.length )
                
              
          
            //  }

        },

        ////获取vr详情数据
        // async getVrDetailData(id:string){
        //     var res = await getVrInfo(id) as any;
        //     if (res.code == 200) {
        //         let data = decryptData(res.data);
        //         this.model = data;
        //         console.log("res=====",this.model)
        //     }
        // },

        ///setVrCollect收藏
       
          
    }, 
    

})
